/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pkl53.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import pkl53.view.Blok123;
import pkl53.view.Blok4;
import pkl53.view.Blok56;
import pkl53.view.Blok5678;
import pkl53.view.Blok78;
import pkl53.view.DataEntriPekerjaanPanel;
import pkl53.view.HomePanel;

/**
 *
 * @author akhul
 */
public class BackupKuesioner {

    private static Blok123 blok123;
    private static Blok4 blok4;
    private static Blok56 blok56;
    private static Blok5678 blok5678;
   
    /**
     * Untuk membaca database.properties yang berisi konfigurasi koneksi
     * database
     */
    public static void read() {
        blok123 = DataEntriPekerjaanPanel.getBlok123();
        blok4 = DataEntriPekerjaanPanel.getBlok4();
        blok56 = DataEntriPekerjaanPanel.getBlok56();
        //blok5678 = DataEntriPekerjaanPanel.getBlok5678();
        //String fileSeparator = System.getProperty("file.separator");
        try {
            //String backupDir1 = "D://yopi.7gp";
            
            String name = HomePanel.getPathTextField().getText();
            if(name.equals("")){
//                Message.errorMessage("Please chose the file first!");
            }
            
            Properties properties = new Properties();
            properties.load(new FileInputStream(name));
            
            blok123.getB1R1().setText(properties.getProperty("B1R1"));
            blok123.getB1R2().setText(properties.getProperty("B1R2"));
            blok123.getB1R3().setText(properties.getProperty("B1R3"));
            blok123.getB1R4().setText(properties.getProperty("B1R4"));
            blok123.getB1R5().setText(properties.getProperty("B1R5A"));
            blok123.getB1R6().setText(properties.getProperty("B1R5B"));
            blok123.getB1R7().setText(properties.getProperty("B1R6"));

            blok5678.getB5R1().setText(properties.getProperty("B5R1"));
            blok5678.getB5R2().setText(properties.getProperty("B5R2"));
            blok5678.getB5R3().setText(properties.getProperty("B5R3"));
            blok5678.getB5R4().setText(properties.getProperty("B5R4"));
            blok5678.getB5R5().setText(properties.getProperty("B5R5"));
            blok5678.getB5R6().setText(properties.getProperty("B5R6"));
            blok5678.getB5R7().setText(properties.getProperty("B5R7"));
            blok5678.getB5R8().setText(properties.getProperty("B5R8"));
            blok5678.getB5R9().setText(properties.getProperty("B5R9"));
            blok5678.getB5R10().setText(properties.getProperty("B5R10"));
            blok5678.getB5R11().setText(properties.getProperty("B5R11"));
            blok5678.getB5R12a().setText(properties.getProperty("B5R12a"));
            blok5678.getB5R12b().setText(properties.getProperty("B5R12b"));
            blok5678.getB6R1().setText(properties.getProperty("B6R1"));
            blok5678.getB6R2().setText(properties.getProperty("B6R2"));
            blok5678.getB6R3().setText(properties.getProperty("B6R3"));
            blok5678.getB6R4().setText(properties.getProperty("B6R4"));
            blok5678.getB6R5().setText(properties.getProperty("B6R5"));
            blok5678.getB6R6().setText(properties.getProperty("B6R6"));
            blok5678.getB6R7().setText(properties.getProperty("B6R7"));
            blok5678.getB6R8().setText(properties.getProperty("B6R8"));
            blok5678.getB6R9().setText(properties.getProperty("B6R9"));
            blok5678.getB6R10a().setText(properties.getProperty("B6R10a"));
            blok5678.getB6R10b().setText(properties.getProperty("B6R10b"));
            blok5678.getB6R11().setText(properties.getProperty("B6R11"));
            blok5678.getB6R12().setText(properties.getProperty("B6R12"));
            blok5678.getB6R13().setText(properties.getProperty("B6R13"));
            
            blok5678.getB6R14a().setText(properties.getProperty("B6R14a"));
            blok5678.getB6R14b().setText(properties.getProperty("B6R14b"));
            blok5678.getB6R15().setText(properties.getProperty("B6R15"));
            blok5678.getB6R16().setText(properties.getProperty("B6R16"));
            blok5678.getB6R17().setText(properties.getProperty("B6R17"));
            blok5678.getB6R18().setText(properties.getProperty("B6R18"));
            blok5678.getB6R19().setText(properties.getProperty("B6R19"));
            blok5678.getB6R20().setText(properties.getProperty("B6R20"));
            blok5678.getB6R21a().setText(properties.getProperty("B6R21a"));
            blok5678.getB6R21b().setText(properties.getProperty("B6R21b"));
            blok5678.getB6R22().setText(properties.getProperty("B6R22"));
            blok5678.getB6R23().setText(properties.getProperty("B6R23"));
            blok5678.getB6R24().setText(properties.getProperty("B6R24"));
            blok5678.getB6R25a().setText(properties.getProperty("B6R25a"));
            blok5678.getB6R25b().setText(properties.getProperty("B6R25b"));
            blok5678.getB7R1().setText(properties.getProperty("B7R1"));
            blok5678.getB7R2().setText(properties.getProperty("B7R2"));
            blok5678.getB7R3().setText(properties.getProperty("B7R3"));
            blok5678.getB7R4().setText(properties.getProperty("B7R4"));
            blok5678.getB7R5().setText(properties.getProperty("B7R5"));
            blok5678.getB7R7().setText(properties.getProperty("B7R7"));

  //          Message.infoMessage("<html><p>Success import the file <br> KKS: "+name);
        } catch (Exception ex) {
            ex.printStackTrace();
    //        Message.errorMessage("Import file failed");
        }
    }

    /**
     * Kalo yang ini untuk menulis konfigurasi databasenya
     */
    public static void write() {
        blok123 = DataEntriPekerjaanPanel.getBlok123();
        blok4 = DataEntriPekerjaanPanel.getBlok4();
        blok56 = DataEntriPekerjaanPanel.getBlok56();
        //blok5678 = DataEntriPekerjaanPanel.getBlok5678();
        String fileSeparator = System.getProperty("file.separator");
        try {
            String backupDir1 = System.getProperty("user.home") + fileSeparator + ".data-entry-pkl53";
            File f = new File(backupDir1);
            if (!f.exists()) {
                f.mkdir();
            }
            
            String kks = blok123.getB1R1().getText()+blok123.getB1R2().getText()+
                    blok123.getB1R3().getText()+blok123.getB1R4().getText()+
                    blok123.getB1R5().getText()+blok123.getB1R6().getText()+
                    blok123.getB1R7().getText();
            Properties properties = new Properties();
            
            properties.setProperty("B1R1", blok123.getB1R1().getText());
            properties.setProperty("B1R2", blok123.getB1R2().getText());
            properties.setProperty("B1R3", blok123.getB1R3().getText());
            properties.setProperty("B1R4", blok123.getB1R4().getText());
            properties.setProperty("B1R5A", blok123.getB1R5().getText());
            properties.setProperty("B1R5B", blok123.getB1R6().getText());
            properties.setProperty("B1R6", blok123.getB1R7().getText());
            properties.setProperty("B1R7", blok123.getB1R8().getText());
            properties.setProperty("B1R8", blok123.getB1R9().getText());
            properties.setProperty("B1R9", blok123.getB1R10().getText());
            properties.setProperty("B2R1", blok123.getB2R1().getText());
            properties.setProperty("B2R2", blok123.getB2R2().getText());
            properties.setProperty("B3R1C1", blok123.getB3R1C1().getText());
            properties.setProperty("B3R1C2", blok123.getB3R1C2().getText());
            properties.setProperty("B3R2C1", blok123.getB3R2C1().getText());
            properties.setProperty("B3R2C2", blok123.getB3R2C2().getText());
            properties.setProperty("B3R3C1a", blok123.getB3R3C1a().getText());
            properties.setProperty("B3R3C1b", blok123.getB3R3C1b().getText());
            properties.setProperty("B3R3C2a", blok123.getB3R3C2a().getText());
            properties.setProperty("B3R3C2b", blok123.getB3R3C2b().getText());
            
            //BLOK 4 Belum
            
            properties.setProperty("B5R1", blok5678.getB5R1().getText());
            properties.setProperty("B5R2", blok5678.getB5R2().getText());
            properties.setProperty("B5R3", blok5678.getB5R3().getText());
            properties.setProperty("B5R4", blok5678.getB5R4().getText());
            properties.setProperty("B5R5", blok5678.getB5R5().getText());
            properties.setProperty("B5R6", blok5678.getB5R6().getText());
            properties.setProperty("B5R7", blok5678.getB5R7().getText());
            properties.setProperty("B5R8", blok5678.getB5R8().getText());
            properties.setProperty("B5R9", blok5678.getB5R9().getText());
            properties.setProperty("B5R10", blok5678.getB5R10().getText());
            properties.setProperty("B5R11", blok5678.getB5R11().getText());
            properties.setProperty("B5R12a", blok5678.getB5R12a().getText());
            properties.setProperty("B5R12b", blok5678.getB5R12b().getText());
            properties.setProperty("B6R1", blok5678.getB6R1().getText());
            properties.setProperty("B6R2", blok5678.getB6R2().getText());
            properties.setProperty("B6R3", blok5678.getB6R3().getText());
            properties.setProperty("B6R4", blok5678.getB6R4().getText());
            properties.setProperty("B6R5", blok5678.getB6R5().getText());
            properties.setProperty("B6R6", blok5678.getB6R6().getText());
            properties.setProperty("B6R7", blok5678.getB6R7().getText());
            properties.setProperty("B6R8", blok5678.getB6R8().getText());
            properties.setProperty("B6R9", blok5678.getB6R9().getText());
            properties.setProperty("B6R10a", blok5678.getB6R10a().getText());
            properties.setProperty("B6R10b", blok5678.getB6R10b().getText());
            properties.setProperty("B6R11", blok5678.getB6R11().getText());
            properties.setProperty("B6R12", blok5678.getB6R12().getText());
            properties.setProperty("B6R13", blok5678.getB6R13().getText());
            
            properties.setProperty("B6R14a", blok5678.getB6R14a().getText());
            properties.setProperty("B6R14b", blok5678.getB6R14b().getText());
            properties.setProperty("B6R15", blok5678.getB6R15().getText());
            properties.setProperty("B6R16", blok5678.getB6R16().getText());
            properties.setProperty("B6R17", blok5678.getB6R17().getText());
            properties.setProperty("B6R18", blok5678.getB6R18().getText());
            properties.setProperty("B6R19", blok5678.getB6R19().getText());
            properties.setProperty("B6R20", blok5678.getB6R20().getText());
            properties.setProperty("B6R21a", blok5678.getB6R21a().getText());
            properties.setProperty("B6R21b", blok5678.getB6R21b().getText());
            properties.setProperty("B6R22", blok5678.getB6R22().getText());
            properties.setProperty("B6R23", blok5678.getB6R23().getText());
            properties.setProperty("B6R24", blok5678.getB6R24().getText());
            properties.setProperty("B6R25a", blok5678.getB6R25a().getText());
            properties.setProperty("B6R25b", blok5678.getB6R25b().getText());
            properties.setProperty("B7R1", blok5678.getB7R1().getText());
            properties.setProperty("B7R2", blok5678.getB7R2().getText());
            properties.setProperty("B7R3", blok5678.getB7R3().getText());
            properties.setProperty("B7R4", blok5678.getB7R4().getText());
            properties.setProperty("B7R5", blok5678.getB7R5().getText());
            properties.setProperty("B7R7", blok5678.getB7R7().getText());


            properties.store(new FileOutputStream(backupDir1 + "/" + kks + ".p53"), kks);
//            System.out.println("BackUp Success");
        } catch (IOException ex) {
//            System.out.println("BackUp Failed");
        }
    }

    /**
     * @param aBlok123 the blok123 to set
     */
    public static void setBlok123(Blok123 aBlok123) {
        blok123 = aBlok123;
    }

    /**
     * @param aBlok4 the blok4 to set
     */
    public static void setBlok4(Blok4 aBlok4) {
        blok4 = aBlok4;
    }

    /**
     * @param aBlok56 the blok56 to set
     */
    public static void setBlok56(Blok56 aBlok56) {
        blok56 = aBlok56;
    }
    
    /**
     * @param aBlok5678 the blok5678 to set
     */
    public static void setBlok5678(Blok5678 aBlok5678) {
        blok5678 = aBlok5678;
    }


}
